<?php
require_once('inc/init.php');
require_once('inc/pager.php');
require_once getCacheFilePath('forums.php');
require_once('inc/editor/ubb.php');

//允许查看用户资料
if(getPopedom(2)==0){
	printMsg('popedom_2');
}

$uid=numFilter($_GET['uid']);
$username=strFilter($_GET['username']);
if($uid>0){
	$user=$db->row_select_one("users","id={$uid}");
}elseif(!empty($username)){
	$user=$db->row_select_one("users","username='{$username}'");
}
if(empty($user)){
	printMsg('user_noexist');
}
$view_fids=array();
foreach($cache_forums as $_forum){
	if(!empty($_forum['forumpass']) || !empty($_forum['forumusers']) || !empty($_forum['forumgroups'])){
		continue;
	}
	array_push($view_fids, $_forum['id']);
}


$headtitle = "查看".htmlFilter($user['username'])."的资料";
$headkeywords="查看".htmlFilter($user['username'])."的资料,".htmlFilter(strip_tags($user['usertitle'])).",".strip_tags($ubb->ubb2html($user['signature'])).",";
$headdesc="查看".htmlFilter($user['username'])."的资料,".htmlFilter(strip_tags($user['usertitle'])).",".strip_tags($ubb->ubb2html($user['signature'])).",";
$user['signuptime']=getDateStr($user['signuptime'],'dateonly');
$user['userurl']=genUrl("user.php?uid={$user['id']}");
$user['username']=htmlFilter($user['username']);
$fans_rows=$db->row_select("fans,users","fans.userid={$user['id']} and fans.fanid=users.id",8,"*","users.lastlogintime desc");
$fans_count=$db->row_select_one("fans","userid={$user['id']}","count(0) as c");
$fans_count=$fans_count['c'];

$condition="topics.userid={$user['id']} and topics.isrecycle=0 and topics.verifystate=0 and topics.id=posts.tid and posts.istopic=1";
$curPage = numFilter($_GET["page"]);
$pager = new Pager();
$pager->init($cache_settings['topicspernum'],$curPage,genUrl("user.php?uid={$user['id']}&page={page}"));
$topicsrow = $pager->queryRows($db, "topics,posts", $condition,  "*,topics.id as id", "topics.id desc",100);

$memberstr.=	"<dl class='view_a3'>".
						"<dt>帖子</dt><dd>{$user['postsnum']}&nbsp;</dd>";
foreach($cache_credits as $credits){
	$memberstr.="<dt>{$credits['creditsname']}</dt><dd>{$user[$credits['creditscode']]}&nbsp;</dd>";
}
if(!empty($user['usertitle'])){
	$memberstr.=	"<dt>头衔</dt><dd><span style='color:{$cache_groups[$user[groupid]][color]}'>".htmlFilter($user['usertitle'])."</span>&nbsp;</dd>";
}
$memberstr.=	"<dt>注册</dt><dd>{$user['signuptime']}&nbsp;</dd>".
						"</dl>";
$starimg=getStar($cache_groups[$user[groupid]][starnum]);

$topic_rows=array();
foreach($topicsrow as $key=>$topic){
	if(!in_array($topic['fid'],$view_fids)){
		continue;
	}
	$tid=$topic['id'];
	$topic['title']=htmlFilter($topic['title']);
	//$topic['content']='';
	$topic['content']=$ubb->ubb2html($topic['content']);
	$topic['posttime']=getDateStr($topic['posttime']);
	$topic['icon']=getTopicIcon($topic);
	$topic['forumurl']=genUrl("forum.php?fid={$topic['fid']}");
	$topic['viewurl']=genUrl("view.php?tid={$topic['id']}");
	array_push($topic_rows, $topic);
}

$writemsg=isLogin()?"<a href=\"javascript:void(0);\" onclick=\"sendUserMsg('{$user['username']}')\" class=\"writemsg\" title=\"给{$user['username']}发送站内短信\"></a>":"";
require_once('header.php');
require_once getTemplatePath('user.htm');
footer();
?>